package com.wangyb.wework.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.wangyb.wework.entity.contact.WwContact;
import com.wangyb.wework.entity.employee.WwEmployee;
import com.wangyb.wework.service.IWwEmployeeService;
import com.wangyb.wework.service.contact.IWwContactEmployeeService;
import com.wangyb.wework.service.contact.IWwContactService;
import com.wangyb.wework.vo.MeidaVo;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;


/**
 * @Author: wangyb
 * @Date: 2021/8/4 10:25 上午
 */
@Api(value = "侧边栏一客一码控制器", tags = {"侧边栏一客一码控制器"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Slf4j
@RestController
public class YiKeYiMaController {
	@Autowired
	private IWwEmployeeService iWwEmployeeService;
	@Autowired
	private IWwContactService iWwContactService;
	@Autowired
	private IWwContactEmployeeService iWwContactEmployeeService;

	@Autowired
	private TokenService tokenService;

	@GetMapping("/yikeyima/qrCodeCard")
	public AjaxResult qrCodeCard(@NotBlank(message = "客户id 不能为空") String contactId,@RequestParam(required = false,defaultValue = "false") Boolean refreshAvatar){
		LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
		SysUser user = loginUser.getUser();
		WwEmployee employee = iWwEmployeeService.getByUserId(user.getUserId());
		WwContact contact = iWwContactService.getById(contactId);
		MeidaVo mediaVo = iWwContactEmployeeService.getQrCodeCardUrl(employee, contact,refreshAvatar);
		return AjaxResult.success(mediaVo);
	}
}
